package com.gx.smart.building.ui.assets.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemAssetInspectionRecordLayoutBinding;
import com.huishi.gx.ib.grpc.lib.ib.asset.asset.v1.PlanRecordDto;

/**
 * @author xiaosy
 * @create 2020/5/8
 * @Describe 维修详情
 **/
public class InspectionRecordAdapter extends BaseAdapter<PlanRecordDto, InspectionRecordAdapter.ViewHolder> {
    public InspectionRecordAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_asset_inspection_record_layout;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemAssetInspectionRecordLayoutBinding binding = ItemAssetInspectionRecordLayoutBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, PlanRecordDto item, int position) {
        String handleTime = item.getHandleTime();
        if (!TextUtils.isEmpty(handleTime)) {
            String time = TimeUtils.millis2String(Long.parseLong(handleTime), "yyyy年MM月dd日");
            holder.binding.handleTime.setText(time);
        }

        holder.binding.handleUserName.setText("操作人: " + item.getHandleUserName());
    }

    protected static class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemAssetInspectionRecordLayoutBinding binding;

        public ViewHolder(ItemAssetInspectionRecordLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
